package com.heima.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heima.mapper.TbOrderMapper;
import com.heima.pojo.TbOrder;
import com.heima.service.ITbOrderService;
import com.heima.util.LocalDateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author nan
 * @since 2024-06-11
 */
@Service
public class TbOrderServiceImpl extends ServiceImpl<TbOrderMapper, TbOrder> implements ITbOrderService {

    @Autowired
    private TbOrderMapper orderMapper;

    /**
     * 统计当月订单总量
     *
     * @param start
     * @param end
     * @return
     */
    @Override
    public Long getOrderCount(String start, String end) {
        LocalDate startTime = LocalDateUtil.parse(start);
        LocalDate endTime = LocalDateUtil.parse(end);
        Long orderCount = orderMapper.getOrderCount(startTime, endTime);
        if (orderCount == null) {
            return 0L;
        }
        return orderCount;
    }

    /**
     * 查询当月销售额
     *
     * @param start
     * @param end
     * @return
     */
    @Override
    public Long getOrderAmount(String start, String end) {
        LocalDate startTime = LocalDateUtil.parse(start);
        LocalDate endTime = LocalDateUtil.parse(end);
        Long orderAmount = orderMapper.getOrderAmount(startTime, endTime);
        if (orderAmount == null) {
            return 0L;
        }
        return orderAmount;
    }
}
